package com.abiao.demo.service.impl;

import com.abiao.demo.domain.User;
import com.abiao.demo.mapper.UserMapper;
import com.abiao.demo.service.UserService;
import com.abiao.demo.util.ConversionUtil;
import com.abiao.demo.vo.UserVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: luobiao
 * @date: 2022-01-24 16:04
 **/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public int insertUser(User user) {
        return baseMapper.insert(user);
    }

    @Override
    public int updateUser(User user) {
        return baseMapper.updateById(user);
    }

    @Override
    public int deleteUser(User user) {
        return baseMapper.deleteById(user.getUserId());
    }

    @Override
    public User findUserByName(String userName) {
        return userMapper.getUserByName(userName);
    }

    @Override
    public User getUserById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<UserVO> getUserList() {
        List<User> users = baseMapper.selectList(new LambdaQueryWrapper<User>());
//        List<User> users = userMapper.selectUserList();
        List<UserVO> userVOS = ConversionUtil.batchApply(users, UserVO.class);
        return userVOS;
    }
}
